﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TeenyGrab.Interfaces;
using TeenyGrab.Objects;
using TeenyGrab.Helpers;
using TeenyGrab.Windows;

namespace TeenyGrab.Inputs
{
    [Serializable]
    public class PartialScreenInput : IInput
    {
        public bool Configurable { get { return true; } set { } }
        
        public Area Area { get; set; }
        public bool PickEveryTime { get; set; }

        public string Name { get { return "Partial screen"; } set { } }

        public string Description { get { return "Takes a screenshot of a specific part of the screen."; } set { } }


        public PartialScreenInput()
        {
            Area = new Area();
            PickEveryTime = true;
        }

        public void Configure()
        {
            var config = new ConfigurePartialScreenInputWindow(this);
            config.ShowDialog();
        }

        public ImageObject Get()
        {
            var screenCapture = new ScreenCapture();
            var image = screenCapture.CaptureAllScreens();
            var area = Area;

            if(PickEveryTime)
            {
                var areaSelector = new AreaSelectorWindow(image);
                if(areaSelector.ShowDialog() == true)
                {
                    area = areaSelector.Area;
                }
                else
                {
                    return null;
                }
            }

            image = image.Crop(area);

            return new ImageObject()
            {
                Image = image,
            };
        }
    }
}
